package com.example.springbootdatamock.mock;

import com.apifan.common.random.RandomSource;
import com.apifan.common.random.source.AreaSource;
import com.example.springbootdatamock.bean.HiveData;
import com.example.springbootdatamock.mapper.HiveMapper;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Value;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.stream.Collectors;


public class HiveMocker {
    private HiveMapper hiveMapper;
    @Value("${dataCount.hiveDataCount}")
    private Integer hiveDataCount;

    public void mock() {
         this.hiveMapper.createTable();
         AreaSource areaSource = RandomSource.areaSource();

         ArrayList<HiveData> datas = new ArrayList<>();

        for (Integer i = Integer.valueOf(0); i.intValue() < this.hiveDataCount.intValue();  Integer.valueOf(i.intValue() + 1)) {
            Integer integer1, integer2;
             String[] addrs = areaSource.randomCity(",").split(",");
             datas.add(new HiveData(addrs[0], addrs[1], Integer.valueOf(RandomUtils.nextInt(1, 100))));
        }



        String sql = datas.stream().map(d -> String.format(" ('%s','%s', %s ) ", new Object[]{d.getProvince(), d.getCity(), d.getPerc()})).collect(Collectors.joining(","));

         this.hiveMapper.insertData(LocalDate.now().toString(), sql);
    }
}



 